package com.feng.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ObjectMapperUtils {

    public static <T> String getObjectJson(Object o) {
        ObjectMapper mapper = new ObjectMapper();
        String s;
        try {
            s = mapper.writeValueAsString(o);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        return s;
    }

    public static <T> T getObjectObject(Object o, Class<T> clazz){
        ObjectMapper mapper = new ObjectMapper();
        T t = mapper.convertValue(o, clazz);
        return t;
    }
}
